home *** CD-ROM | disk | FTP | other *** search
/ SGI Enlighten DSM 3.1 / SGI EnlightenDSM 3.1.iso / SCO5X / INSTALL / .deinstall
Text File  |  1999-04-16  |  13KB  |  547 lines

  1. #!/bin/sh
  2. #
  3. # Script: .deinstall
  4. #
  5. # deinstall does the following:
  6. #
  7. # 1) stops all Enlighten daemons 
  8. # 2) removes rc references entered by e_putrc
  9. # 3) removes the dbenl and informix user accounts
  10. # 4) removes the enlighten and emd directories 
  11. # 5) removes the /etc/enlighten file
  12. #
  13. # grep for 'Main' for the start of the script.
  14. #
  15. # Copyright (c) 1990-1999 Enlighten Software Solutions, Inc.
  16. # All Rights Reserved.
  17. #
  18. # 1aug96 mrm
  19. # 14jan97 mrm - incorporated AIX rc.nfs fix
  20. # 23jan97 mrm - added OSF support
  21. # 23jan97 mrm - moved rc references to rc3.d where applicable.
  22.  
  23. PATH=/bin:/usr/bin:/etc:/usr/ucb:/usr/bsd:/usr/etc:$PATH
  24. export PATH
  25.  
  26.  
  27. # OS-specific setup
  28.  
  29. case "`echo 'a\c'`" in
  30.     'a\c') 
  31.         ECHO="echo -n"
  32.         NO_NL=""
  33.         ;;
  34.     * ) 
  35.         ECHO="echo"
  36.         NO_NL="\c"
  37.         ;;
  38. esac
  39.  
  40. PSOPTS="-e"
  41. PIDCOLUMN=1
  42.  
  43. if [ "$OS" = "SunOS" ]; then
  44.     case "$REV" in
  45.         4.1.* )
  46.             PSOPTS="-axuww"
  47.             PIDCOLUMN=2
  48.             ;;
  49.     esac
  50. fi
  51.  
  52. errorCheck () {
  53.     #
  54.     # errorCheck can be used for all commands except grep
  55.     #
  56.     if [ $? -ne 0 ] ; then
  57.         echo "$appName: Fatal: Could not deinstall Enlighten." 1>&2
  58.         exit 1
  59.     fi
  60. }
  61.  
  62. errorCheck2 () {
  63.     #
  64.     # errorCheck can be used for grep, which returns 2 on error
  65.     #
  66.     if [ $? -eq 2 ] ; then
  67.         echo "$appName: Fatal: Could not deinstall Enlighten." 1>&2
  68.         exit 1
  69.     fi
  70. }
  71.  
  72. should_i_continue () {
  73.     if [ $verbose -eq 1 ] ; then
  74.         $ECHO "$appName: [y|n|exit] (default is 'y') > $NO_NL"
  75.         read response;
  76.         case "$response" in
  77.             "" | y* | Y* )
  78.                 CONTINUE=yes
  79.                 ;;
  80.             n* | N* )
  81.                 echo "$appName: Deinstallation of Enlighten will not be complete."
  82.                 CONTINUE=no 
  83.                 ;;
  84.             * )
  85.                 echo "$appName: Exitting."
  86.                 echo
  87.                 exit 2
  88.                 ;;
  89.         esac
  90.     else
  91.         CONTINUE=yes
  92.     fi
  93. }
  94.  
  95. VerifyUserIsRoot () {
  96.     USER_ID=`id | tr "(" "=" | cut "-d=" -f2`
  97.      
  98.     if [ ! $USER_ID = 0 ] ; then
  99.         echo
  100.         echo "### $appName must be run by the 'root' superuser."
  101.         echo "    Please login as root and try again."
  102.         echo
  103.         echo "Exitting.  All partitions left untouched."
  104.         echo
  105.         exit 2
  106.     fi
  107. }
  108.  
  109. VerifyScriptIsRunningFromTmpDir () {
  110.     if [ ! "$fullAppDirName" = "$ENLIGHTEN" -o ! `pwd` = "$ENLIGHTEN" ] ; then
  111.         if [ -f $ENLIGHTEN/$appName ] ; then
  112.             rm /$ENLIGHTEN/$appName
  113.         fi
  114.         cp $fullAppDirName/$appName $ENLIGHTEN/$appName
  115.         chmod 700 $ENLIGHTEN/$appName
  116.  
  117.         if [ -x $ENLIGHTEN/$appName ] ; then
  118.             echo "Please cd into $ENLIGHTEN and invoke ./$appName to deinstall Enlighten."
  119.             exit 0
  120.         else
  121.             echo "$appName: Fatal: Could not copy $appName to $ENLIGHTEN."
  122.             echo "$appName: This script must be copied into $ENLIGHTEN to run."
  123.             exit 1
  124.         fi
  125.     fi
  126. }
  127.  
  128. #
  129. # Put the pid(s) of process(es) from $procs into $pid
  130. #
  131. getPid() {
  132.  
  133.     # Search for:
  134.     # bin/renld -v 0
  135.     # renld -v 0
  136.     # renld
  137.  
  138.     psList=`ps $PSOPTS | egrep -v "$appName|grep"`
  139.     pid=""
  140.  
  141.     for i in $procs ; do
  142.         newpid=`echo "$psList" | egrep "\/$i | $i |[\/ ]$i$" | \
  143.             sed -e 's/^  *//' -e 's/ .*//'`
  144.         pid="$pid $newpid"
  145.         #echo $i is pid $newpid.
  146.     done
  147.     pid=`echo $pid`
  148. }
  149.  
  150. #
  151. # Kill process(es) in $procs.
  152. #
  153. killProcs() {
  154.     getPid $procs
  155.     if [ -n "$pid" ] ; then
  156.         if [ "$KILLOPTS" = "-9" -o "$KILLOPTS" = "-KILL" ] ; then
  157.             echo "$appName: Killing the following processes:"
  158.         else
  159.             echo "$appName: Stopping the following processes:"
  160.         fi
  161.         echo "$psList" | grep PID
  162.         for i in $pid ; do
  163.             echo "$psList" | grep $i
  164.             kill $KILLOPTS $i
  165.         done
  166.     fi
  167. }
  168.  
  169. export procs pid psList KILLOPTS
  170.  
  171. StopENlightenProcesses () {
  172.  
  173.     KILLOPTS="-9"
  174.     procs="xenln sm enl_xinstall renldc"
  175.     killProcs
  176.  
  177.     if [ -x $ENLIGHTEN/bin/stop_enl_daemons ] ; then
  178.         $ENLIGHTEN/bin/stop_enl_daemons
  179.         errorCheck
  180.     elif [ -x $EMD_DIR/bin/stop_enl_daemons ] ; then
  181.         $EMD_DIR/bin/stop_enl_daemons
  182.         errorCheck
  183.     else
  184.         echo "$appName: 'stop_enl_daemons' was missing."
  185.         echo "$appName: 'rm' may fail if Enlighten processes are still active."
  186.     fi
  187. }
  188.  
  189. cleanup_rc() {
  190.  
  191.     if [ -f $RC_DIR/$RC_FILE ] ; then
  192.         echo "$appName: Remove Enlighten references from $RC_DIR/$RC_FILE?"
  193.         should_i_continue
  194.         if [ $CONTINUE = yes ] ; then
  195.             if [ "$RC_FILE" = "S92startenl" -o "$RC_FILE" = "S920enlighten" ] ; then
  196.                 mv $RC_DIR/$RC_FILE /tmp/$RC_FILE.old ; errorCheck
  197.                 echo "$appName: $RC_DIR/$RC_FILE was archived to /tmp/$RC_FILE.old"
  198.             elif [ "$RC_FILE" = "enlighten" ] ; then
  199.                 mv $RC_DIR/$RC_FILE /tmp/$RC_FILE.old ; errorCheck
  200.                 echo "$appName: $RC_DIR/$RC_FILE was archived to /tmp/$RC_FILE.old"
  201.                 rm $LINK_DIR/$LINK_FILE ; errorCheck
  202.                 echo "$appName: $LINK_DIR/$LINK_FILE was removed."
  203.                 rm $LINK_DIR_STOP/$LINK_FILE_STOP ; errorCheck
  204.                 echo "$appName: $LINK_DIR_STOP/$LINK_FILE_STOP was removed."
  205.             else
  206.                 cp $RC_DIR/$RC_FILE $RC_DIR/$RC_FILE.old
  207.                 errorCheck
  208.                 echo "$appName: $RC_DIR/$RC_FILE was archived to $RC_DIR/$RC_FILE.old"
  209.                 egrep -v "S92startenl|start_enl_daemons|start_dsmld" $RC_DIR/$RC_FILE > $RC_DIR/$RC_FILE.new
  210.                 errorCheck2
  211.  
  212.                 mv $RC_DIR/$RC_FILE.new $RC_DIR/$RC_FILE
  213.                 errorCheck
  214.  
  215.                 chown root $RC_DIR/$RC_FILE
  216.                 errorCheck
  217.  
  218.                 chmod 744 $RC_DIR/$RC_FILE
  219.                 errorCheck
  220.             fi
  221.         fi
  222.     fi
  223. }
  224.  
  225. RemoveStartupScripts () {
  226.     
  227.     # Remove rc references
  228.     case `uname -s` in
  229.         OSF1 )
  230.             RC_DIR=/sbin/init.d
  231.             RC_FILE=enlighten
  232.             LINK_FILE=S920enlighten
  233.             LINK_DIR=/sbin/rc3.d
  234.             LINK_FILE_STOP=K12enlighten
  235.             LINK_DIR_STOP=/sbin/rc0.d
  236.             ;;
  237.         HP-UX ) 
  238.             case `uname -r` in
  239.                 ?.10.* )
  240.                     RC_DIR=/sbin/init.d ; export RC_DIR
  241.                     RC_FILE=enlighten ; export RC_FILE
  242.                     LINK_DIR=/sbin/rc2.d ; export LINK_DIR
  243.                     LINK_FILE=S920enlighten ; export LINK_FILE
  244.                     LINK_FILE_STOP=K12enlighten ; export LINK_FILE_STOP
  245.                     LINK_DIR_STOP=/sbin/rc0.d ; export LINK_DIR_STOP
  246.                     ;;
  247.                 * )
  248.                     RC_DIR=/etc ; export RC_DIR
  249.                     RC_FILE=rc ; export RC_FILE
  250.                     ;;
  251.             esac
  252.             ;;
  253.         AIX )
  254.             # There may be entries in rc.nfs or rc.tcpip.
  255.             RC_DIR=/etc ; export RC_DIR
  256.             RC_FILE=rc.tcpip ; export RC_FILE
  257.             cleanup_rc
  258.  
  259.             RC_DIR=/etc ; export RC_DIR
  260.             RC_FILE=rc.nfs ; export RC_FILE
  261.             ;;
  262.         IRIX* )
  263.             RC_DIR=/etc/init.d
  264.             RC_FILE=enlighten
  265.             LINK_FILE=S920enlighten
  266.             LINK_DIR=/etc/rc2.d
  267.             LINK_FILE_STOP=K12enlighten
  268.             LINK_DIR_STOP=/etc/rc0.d
  269.             ;;
  270.         * )
  271.             if [ -d /etc/rc2.d ] ; then
  272.                 RC_DIR=/etc/rc2.d ; export RC_DIR
  273.                 RC_FILE=S92startenl ; export RC_FILE
  274.                 cleanup_rc
  275.                 RC_FILE=S920enlighten ; export RC_FILE
  276.             else
  277.                 RC_DIR=/etc ; export RC_DIR
  278.                 RC_FILE=rc.local ; export RC_FILE
  279.             fi
  280.             ;;
  281.     esac
  282.  
  283.     cleanup_rc
  284. }
  285.  
  286. RemoveEMDUsers () {
  287.  
  288.     # remove the dbenl and informix user accounts
  289.     #
  290.     # (Only remove dbenl and informix if this host has an emd_dir.)
  291.  
  292.     if [ ! -z "$EMD_DIR" ] ; then
  293.  
  294.         # If suites install, drop the database before we
  295.         # begin to remove the dbenl account
  296.  
  297.         suites=false
  298.  
  299.         if [ ! -d $EMD_DIR/informix ] ; then
  300.             suites=true
  301.             echo "Delete the database 'enlightn' ?"
  302.             should_i_continue
  303.             if [ $CONTINUE = yes ] ; then
  304.                 su dbenl -c ". $EMD_DIR/.profile ; db2 'DROP DATABASE enlightn'"
  305.                 if [ "$?" != 0 ] ; then
  306.                     echo "$appName: Error: Unable to delete database."
  307.                 fi
  308.             fi
  309.         fi
  310.         
  311.         # Remove the dbenl accounts
  312.  
  313.         if [ -z "`egrep '^dbenl:' /etc/passwd /etc/group`" ] ; then
  314.             echo "$appName: Error: The 'dbenl' user was missing."
  315.         else
  316.             echo "$appName: Remove the 'dbenl' user and group account?"
  317.             should_i_continue
  318.             if [ $CONTINUE = yes ] ; then
  319.                 UMASK=`umask`
  320.                 umask 077
  321.                 for i in /etc/passwd /etc/group /etc/shadow ; do
  322.                     if [ -f $i ] ; then
  323.                         cp -p $i $i.old1 ; errorCheck
  324.                         echo "$appName: $i was archived to $i.old1."
  325.  
  326.                         egrep -v "^dbenl:" $i > $i.new
  327.                         errorCheck2
  328.                         mv $i.new $i ; errorCheck
  329.                         case "$i" in
  330.                             /etc/shadow)
  331.                             chown root $i ; errorCheck
  332.                             chmod 400 $i ; errorCheck
  333.                             ;;
  334.                             *)
  335.                             chown root $i ; errorCheck
  336.                             chmod 644 $i ; errorCheck
  337.                             ;;
  338.                         esac
  339.                     fi
  340.                 done
  341.                 umask $UMASK
  342.  
  343.                 # Remove AIX password references in /etc/security/passwd
  344.  
  345.                 if [ -f /etc/security/passwd ] ; then
  346.                     cp -p /etc/security/passwd /etc/security/passwd.old1 
  347.                     errorCheck
  348.                     echo "$appName: /etc/security/passwd was archived to /etc/security/passwd.old1."
  349.                     awk 'BEGIN  { FS = ":" } \
  350.                         NF > 1  { flag = 0 } \
  351.                         /dbenl/ { flag = 1 } \
  352.                         { if ( flag == 0 ) print }' /etc/security/passwd.old1 \
  353.                         > /etc/security/passwd.new
  354.                     errorCheck
  355.                     mv /etc/security/passwd.new /etc/security/passwd ; errorCheck
  356.                     chown root /etc/security/passwd ; errorCheck
  357.                     chgrp security /etc/security/passwd ; errorCheck
  358.                     chmod 400 /etc/security/passwd ; errorCheck
  359.                 fi
  360.             fi
  361.         fi
  362.  
  363.         # Remove the informix accounts
  364.  
  365.         if [ -z "`egrep '^informix:' /etc/passwd /etc/group`" ] ; then
  366.             if [ "$suites" = "false" ] ; then
  367.                 echo "$appName: Error: The 'informix' user was missing."
  368.             fi
  369.         else
  370.             echo "$appName: Remove the 'informix' user and group account?"
  371.             should_i_continue
  372.             if [ $CONTINUE = yes ] ; then
  373.                 UMASK=`umask`
  374.                 umask 077
  375.                 for i in /etc/passwd /etc/group /etc/shadow ; do
  376.                     if [ -f $i ] ; then
  377.                         cp -p $i $i.old2 ; errorCheck
  378.                         echo "$appName: $i was archived to $i.old2."
  379.                         egrep -v "^informix:" $i > $i.new
  380.                         errorCheck2
  381.                         mv $i.new $i ; errorCheck
  382.                         case "$i" in
  383.                             /etc/shadow)
  384.                             chown root $i ; errorCheck
  385.                             chmod 400 $i ; errorCheck
  386.                             ;;
  387.                             *)
  388.                             chown root $i ; errorCheck
  389.                             chmod 644 $i ; errorCheck
  390.                             ;;
  391.                         esac
  392.                     fi
  393.                 done
  394.                 umask $UMASK
  395.  
  396.                 # Remove AIX password references in /etc/security/passwd
  397.  
  398.                 if [ -f /etc/security/passwd ] ; then
  399.                     cp /etc/security/passwd /etc/security/passwd.old2 
  400.                     errorCheck
  401.                     echo "$appName: /etc/security/passwd was archived to /etc/security/passwd.old2."
  402.                     awk 'BEGIN  { FS = ":" } \
  403.                         NF > 1  { flag = 0 } \
  404.                         /informix/ { flag = 1 } \
  405.                         { if ( flag == 0 ) print }' /etc/security/passwd.old2 \
  406.                         > /etc/security/passwd.new
  407.                     errorCheck
  408.                     mv /etc/security/passwd.new /etc/security/passwd ; errorCheck
  409.                     chown root /etc/security/passwd ; errorCheck
  410.                     chgrp security /etc/security/passwd ; errorCheck
  411.                     chmod 400 /etc/security/passwd ; errorCheck
  412.                 fi
  413.             fi
  414.         fi
  415.     fi
  416. }
  417.  
  418. RemoveGroupAccount () {
  419.  
  420.     # remove the enldsm entry from group file
  421.     #
  422.     if [ -z "`egrep '^enldsm:' /etc/group`" ] ; then
  423.     echo "$appName: Error: The 'enldsm' group entry was missing."
  424.     else
  425.     echo "$appName: Remove the 'enldsm' group?"
  426.     should_i_continue
  427.     if [ $CONTINUE = yes ] ; then
  428.         for i in /etc/group ; do
  429.         if [ -f $i ] ; then
  430.             cp -p $i $i.old1 ; errorCheck
  431.             echo "$appName: $i was archived to $i.old1."
  432.  
  433.             egrep -v "^enldsm:" $i > $i.new
  434.             errorCheck2
  435.             mv $i.new $i ; errorCheck
  436.             chown root $i ; errorCheck
  437.             chmod 644 $i ; errorCheck
  438.         fi
  439.         done
  440.     fi
  441.     fi
  442. }
  443.  
  444.  
  445. RemoveENlightenDirectories () {
  446.  
  447.     # Remove the Enlighten and EMD directories 
  448.     if [ ! -z "$ENLIGHTEN" -a -d "$ENLIGHTEN" ] ; then
  449.         echo "$appName: Recursively remove the Enlighten directory $ENLIGHTEN?"
  450.         should_i_continue
  451.         if [ $CONTINUE = yes ] ; then
  452.             rm -rf $ENLIGHTEN/* $ENLIGHTEN/.data
  453.             errorCheck
  454.         fi
  455.     fi
  456.  
  457.     if [ ! -z "$EMD_DIR" -a -d "$EMD_DIR" ] ; then
  458.         echo "$appName: Recursively remove the EMD directory $EMD_DIR?"
  459.         should_i_continue
  460.         if [ $CONTINUE = yes ] ; then
  461.             rm -rf $EMD_DIR
  462.             errorCheck
  463.         fi
  464.     fi
  465.  
  466.     if [ -f /etc/enlighten -a "$CONTINUE" = "yes" ] ; then
  467.         rm /etc/enlighten
  468.         errorCheck
  469.         echo "$appName: Removed /etc/enlighten."
  470.     fi
  471. }
  472.  
  473. #
  474. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  475. # Main Program
  476. #
  477. verbose=1
  478.  
  479. if [ "$1" = "-q" ] ; then
  480.     verbose=0
  481.     exec > /dev/null 2>&1
  482. fi
  483.  
  484. appName=`basename $0`
  485. appDirName=`dirname $0`
  486. fullAppDirName=`cd $appDirName ; pwd`
  487.  
  488. if [ ! -f /etc/enlighten ] ; then
  489.     echo
  490.     echo "$appName: ### The /etc/enlighten file is missing."
  491.     echo "$appName: ### Enlighten is probably not installed on this host."
  492.     echo "$appName: Exitting."
  493.     exit 0
  494. else
  495.     ENLIGHTEN=`egrep "^enlighten=" /etc/enlighten | cut "-d=" -f2-` 
  496.     EMD_DIR=`egrep "^emd_dir=" /etc/enlighten | cut "-d=" -f2-`
  497.     export ENLIGHTEN EMD_DIR
  498. fi
  499.  
  500. VerifyUserIsRoot
  501. VerifyScriptIsRunningFromTmpDir
  502.  
  503. if [ $verbose -eq 1 ] ; then
  504.     $ECHO "$appName: Are you sure you want to deinstall Enlighten? [y|n|exit] $NO_NL" 
  505.     read response;
  506.     case "$response" in
  507.     y* | Y* ) ;;
  508.     * )
  509.         echo "$appName: Cancelled."
  510.         exit 0
  511.         ;;
  512.     esac
  513. fi
  514.  
  515. # Because the following are reversible, don't ask.
  516.  
  517. if [ -n "$EMD_DIR" ] ; then
  518.     if [ ! -f $EMD_DIR/FLEXlm/lmutil ] ; then
  519.         echo "$appName: Unable to find $EMD_DIR/FLEXlm/lmutil."
  520.         echo "$appName: Unable to stop license daemons."
  521.     else
  522.         echo ""
  523.         echo "$appName: Stopping license daemons."
  524.         su dbenl -c "$EMD_DIR/FLEXlm/lmutil lmdown -c $EMD_DIR/FLEXlm/license.dat -q"
  525.         echo ""
  526.     fi
  527. fi
  528.  
  529. StopENlightenProcesses
  530. RemoveStartupScripts
  531.  
  532. RemoveGroupAccount
  533. RemoveEMDUsers
  534. RemoveENlightenDirectories
  535.  
  536. echo "$appName: Finished."
  537. echo
  538.  
  539. echo "All Enlighten files have been deinstalled except for"
  540. echo "the .deinstall script.  Please run the following commands"
  541. echo "to complete the deinstall:"
  542. echo "cd /"
  543. echo "rm -r $ENLIGHTEN"
  544.  
  545. exit 0
  546.  
  547.